package UrlInfo;
use Data::Dumper;
use Moose;

has beginString => ( is => 'rw', isa => 'Int', default => 0 );
has endString	=> ( is => 'rw', isa => 'Int', default => 0 );
has inner		=> ( is => 'rw', isa => 'Str', default => '' );
has args		=> ( is => 'rw', isa => 'HashRef', default => sub { {} } );

sub create
{
	my $self = shift;
	my $url = shift;
	
	$self = new UrlInfo() if !ref $self;
	
	$self->beginString(1) if $url =~ /^\^/;
	$self->endString(1)   if $url =~ /\$$/;
	
	$url = _removeBeginEnd($url);
	
	$url = $self->_extractARGS($url);
	
	$self->inner($url);

	return $self;	
}

sub _extractARGS
{
	my $self = shift;
	my $url = shift;
	
	my @args = $url =~ /A<\w+>/g;

	for( my $i = 0; $i < @args; $i++) { 
		my $arg = $args[$i]; 
		$url =~ s/$arg//;
		$arg =~ s/A<(\w+)>/$1/;
		$self->{args}{$arg} = $i+1;
	}
	
	return $url;
}

sub _removeBeginEnd
{
	my $url = shift;
	
	$url =~ s/^\^//;
	$url =~ s/\$$//;
	
	return $url;	
}

sub re
{
	my $self = shift;
	
	my $begin 	= $self->beginString ? '^' : '';
	my $end		= $self->endString   ? '$' : '';
	my $inner 	= $self->inner;
	
	my $re = qr!${begin}${inner}${end}!;
	return $re;	
}
1;